<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>

<body>
<form class="layui-form" style="padding: 15px;">
    <div class="layui-inline">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-inline">
            <input type="text" id="roleName" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <button class="layui-btn layui-btn-sm"><i class="layui-icon"></i>
    </button>
</form>
<!--表格-->
<table id="roleList" class="layui-hide" lay-filter="role"></table>

<script type="text/html" id="toolbarTable">
    <button class="layui-btn layui-btn-sm" shiro:hasPermission="system:role:add"
            onclick="openWindow('添加角色信息','/venus/system/role/add')"><i
            class="layui-icon"></i>添加
    </button>
</script>

<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<div th:include="include :: footer"></div>
<script>
    var sysUrl = '/venus/system/role';
    layui.use(['table'], function () {
        var table = layui.table;

        table.render({
            id:'roleList',
            elem: '#roleList',
            method: 'post',
            height: 'full-100',
            toolbar: '#toolbarTable',
            defaultToolbar: ['print', 'exports'],
            cellMinWidth: 100,
            url: sysUrl + '/list',
            cols: [
                [
                    {field: 'num', width: 50, title: '序号', type: 'numbers'}
                    , {field: 'roleName', title: '角色名称'}
                    , {field: 'roleKey', title: '角色权限'}
                    , {field: 'roleSort', title: '角色排序'}
                    , {
                    field: 'dataScope', title: '数据范围', templet: function (d) {
                        if ("1" === d.dataScope) {
                            return "所有数据权限";
                        } else if ("2" === d.dataScope) {
                            return "自定数据权限";
                        }
                    }
                }
                    , {
                    field: 'status', title: '角色状态', templet: function (d) {
                        if ("0" === d.status) {
                            return "正常";
                        } else if ("1" === d.status) {
                            return "停用";
                        }
                    }
                }
                    , {
                    field: 'delFlag', title: '删除标志', templet: function (d) {
                        if ("0" === d.delFlag) {
                            return "存在";
                        } else if ("2" === d.delFlag) {
                            return "删除";
                        }
                    }
                }
                    , {fixed: 'right', title: '操作', toolbar: "#toolbar"}
                ]
            ]
            , page: true
        });

        //监听行工具事件
        table.on('tool(role)', function (obj) {
            delAndEdit(sysUrl, obj, 'role');
        });
        //搜索
        $('.layui-form .layui-btn').on('click', function () {
            table.reload('roleList', {
                where: {
                    roleName: $("#roleName").val()
                }
            });
            return false;
        });
    });
</script>
</body>
</html>